home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / cool / ge_cool.lha / GE_COOL2.1 / src / Tree / AVL_Tree.C next >
C/C++ Source or Header  |  1992-05-15  |  2KB  |  54 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12.  
  13. #include <cool/AVL_Tree.h>
  14.  
  15. // CoolAVL_Tree -- Copy constructor
  16.  
  17. template <class Type>
  18. CoolAVL_Tree<Type>::CoolAVL_Tree<Type> (const CoolAVL_Tree<Type>& b)
  19.  : CoolBinary_Tree<Type>(b)
  20. {}                  
  21.  
  22. // CoolAVL_Tree -- Reference to CoolBinary_Tree (Copies BT, and make AVL out of it)
  23.  
  24. template <class Type>
  25. CoolAVL_Tree<Type>::CoolAVL_Tree<Type> (const CoolBinary_Tree<Type>& b)
  26.  : CoolBinary_Tree<Type>(b)
  27. {
  28.   this->balance();                 // Do an AVL balance on new tree
  29. }                  
  30.  
  31.  
  32. // ~CoolAVL_Tree -- Destructor (not inline because it's virtual)
  33. template <class Type>
  34. CoolAVL_Tree<Type>::~CoolAVL_Tree<Type> () {}
  35.  
  36. // balance  -- Rebalance an AVL tree, and then recalculate each node's
  37. //             balance (right subtree depth minus left subtree depth)
  38. // input:      None
  39. // Output:     None
  40.  
  41. template <class Type>
  42. void CoolAVL_Tree<Type>::balance () {
  43.   CoolBinary_Tree<Type>::balance();
  44.   CoolBinary_Tree::calc_depth (this->get_root(), 0, TRUE);
  45. }
  46.  
  47.  
  48. template<class Type> CoolAVL_Tree {
  49. ostream& operator<< (ostream& os, const CoolAVL_Tree<Type>& av) {
  50.   Type##_print_tree((CoolBinary_Node<Type>*)av.get_root(),os);
  51.   return os;
  52. }
  53. }
  54.